package com.ydy.data.controller;

import com.ydy.common.BaseController;
import com.ydy.common.model.User;
import com.ydy.common.util.ParamsUtil;
import com.ydy.common.vo.PageInfo;
import com.ydy.data.service.UserInfoService;
import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.LinkedHashMap;
import java.util.List;

@RestController
public class UserInfoController extends BaseController {

    @Autowired
    private UserInfoService userService;

    /**
     * 查询用户信息
     * @Title: queryUserInfo
     * @author: dy.yin 2021/4/2 9:55
     * @param: [request]
     * @return: java.lang.Object
     * @throws
     */
    @GetMapping("/queryUserInfo")
    public Object queryUserInfo(HttpServletRequest request){
        PageInfo pageInfo = ParamsUtil.getPageInfo(request);
        User user = ParamsUtil.getBeanParam(new User(),request);

        List<User> userList = userService.queryUserInfo(user,pageInfo);
        pageInfo.setPageResult(userList);
        return pageInfo;
    }


    /**
     * 用户新增或者修改
     * @Title: submitUserInfo
     * @author: dy.yin 2021/4/8 10:51
     * @param: [user]
     * @return: java.lang.Object
     * @throws
     */
    @PostMapping("/submitUserInfo")
    public Object submitUserInfo(@RequestBody User user){
        userService.submitUserInfo(user);
        return retResultVo();
    }

    @PostMapping("/deleteUserInfo")
    public Object deleteUserInfo(@RequestBody LinkedHashMap<String,Object> map){
        String userCode = MapUtils.getString(map,"userCode");
        userService.deleteUserInfo(userCode);
        return retResultVo();
    }

}
